<?php

/** Framework_Controller_Exception */
require_once 'Framework/Controller/Action/Exception.php';

/** Framework_Controller_Action */
require_once 'Framework/Controller/Action.php';

abstract class Framework_Controller_Action_Helper_Abstract
{
    /**
     * $_actionController
     *
     * @var Framework_Controller_Action
     */
    protected $_actionController = null;

    /**
     * setActionController()
     *
     * @param Framework_Controller_Action $actionController
     * @return Framework_Controller_ActionHelper_Abstract
     */
    public function setActionController(Framework_Controller_Action $action_controller = null)
    {
        $this->_actionController = $action_controller;
        return $this;
    }

    /**
     * Retrieve current action controller
     *
     * @return Framework_Controller_Action
     */
    public function getActionController()
    {
        return $this->_actionController;
    }

    /**
     * Hook into action controller initialization
     *
     * @return void
     */
    public function init()
    {
    }

    /**
     * Hook into action controller preDispatch() workflow
     *
     * @return void
     */
    public function preDispatch()
    {
    }

    /**
     * Hook into action controller postDispatch() workflow
     *
     * @return void
     */
    public function postDispatch()
    {
    }

    /**
     * getRequest()
     *
     * @return Framework_Controller_Request_Abstract $request
     */
    public function getRequest()
    {
        $controller = $this->getActionController();

        return $controller->getRequest();
    }

    /**
     * getResponse()
     *
     * @return Framework_Controller_Response_Abstract $response
     */
    public function getResponse()
    {
        $controller = $this->getActionController();

        return $controller->getResponse();
    }
    
    /**
     * getName()
     *
     * @return string
     */
    public function getName()
    {
        $full_class_name = get_class($this);

        if (strpos($full_class_name, '_') !== false) {
            $helper_name = strrchr($full_class_name, '_');
            return ltrim($helper_name, '_');
        } else {
            return $full_class_name;
        }
    }
}
